/**
 * Created by Admin on 2018/1/3.
 */
define(function(require,exports,module){
    var commonPaging=require("../common/commonPagingCq");
    var v =require("./targetSetting.validator");
    var tpl=require("./tpl/targetSettingTpl.html");
    var myWidGet = require("../common/myWidGet");
    var template = require("../common/qy-template");
    var uri = require("uri");
    var wlc = window.location;
    var uriParam = uri.getParams(wlc.href, true);

    var p=new commonPaging({
        htmlContainer: "#Js_page_content",
        pageContainer: "#Js_fs_paging",
        url: window.jkconfig.webapiurlv+$("#Js_page_content").attr("data-action"),
        tpl:tpl,
        data:{pageNum:1,pageSize:20,year:uriParam.year}
    });
    p.init();
    // v.editValidator("#targetManageSetting");
    $(function(){
        $("#platformName").html(platformName);
        if(uriParam.type == "setting"){
            $(".btnSave").show();
        }else{
            $(".btnSave").hide();
        }

        $("body").on("click",".btnSave",function(){
            var info = [],state = false;
           $.each( $("#Js_page_content tr"),function(index,element){
               var obj = {};
               $.each($("td",element),function(){
                   var name = $(this).find("input").attr("name");
                   obj[name] = $.trim($(this).find("input").val());
                   var reg = /^[0-9]*$/;
                   if(obj[name] == ""){
                       $.showErr("内容为空,请输入数值！");
                       $(".warning").show();
                       state = true;
                       return false;
                   }else if(!reg.test(obj[name])){
                       state = true;
                       $(".warning").show();
                       return false;
                   }
               })
               info.push(obj);
           })

            if(!state){
                $.ajax({
                    url:window.jkconfig.webapiurlv+"sys/patentIndicatormodify",
                    data:JSON.stringify(info),
                    type:'POST',
                    contentType:"application/json;charset=UTF-8",
                    success:function(data){
                        if(data.code == 0){
                            $.showSuccessTimeout(data.msg ||"保存成功",function(){
                                window.location.reload();
                            });
                        }else{
                            $.showErr(data.msg);
                        }
                    }
                })
            }
        })
    })
})